package cn.itcast.p2p20.bean.request;

import java.util.HashMap;
import java.util.Map;

import cn.itcast.p2p20.net.BaseRequest;
import cn.itcast.p2p20.safe.BytesHelper;
import cn.itcast.p2p20.safe.DigestAlgorithm;
import cn.itcast.p2p20.utils.Constant;

/**
 * Created by Administrator on 2016/7/31.
 */
public class RegisterRequest implements BaseRequest {

    private String username;
    private String password;

    public RegisterRequest(String username, String password) {
        this.username = username;
        this.password = password;
    }

    @Override
    public String getUrl() {
        return Constant.format("RegisterServlet");
    }

    @Override
    public HttpMethod getHttpMethod() {
        return HttpMethod.POST;
    }

    @Override
    public Map<String, String> getParams() {

        Map<String, String> map = new HashMap<String, String>();
        map.put("username", username);
        String hexPassword = BytesHelper.toHex(DigestAlgorithm.MD5.encrypt(BytesHelper.toBytes(password), null));
        map.put("password", hexPassword);
        return map;
    }
}
